
import React from 'react';
import PropTypes from 'prop-types';
import {injectIntl, formatMessage} from './intl';
import {Table} from 'antd';
import {conventEnumValueToString, formatAmount} from '../utils';
import {goodWillDetailType} from '../Enum';
import {TABLE} from '../constants';
/* eslint-disable react/prefer-stateless-function */
const rowKey = record => `${record.partSaleOrderCode}${record.partCode}`;
class DetailTable extends React.PureComponent {
    render() {
        const columns = [
            {
                title: formatMessage({
                    id: 'detailTable.type',
                    defaultMessage: '类型'
                }),
                dataIndex: 'type',
                render: text => conventEnumValueToString(goodWillDetailType, text)
            },
            {
                title: formatMessage({
                    id: 'detailTable.code',
                    defaultMessage: '编号'
                }),
                dataIndex: 'code',
            },
            {
                title: formatMessage({
                    id: 'detailTable.name',
                    defaultMessage: '名称'
                }),
                dataIndex: 'name',
            },
            {
                title: formatMessage({
                    id: 'detailTable.usedQty',
                    defaultMessage: '数量'
                }),
                dataIndex: 'usedQty',
            },
            {
                title: formatMessage({
                    id: 'detailTable.price',
                    defaultMessage: '单价'
                }),
                dataIndex: 'price',
                render: text => formatAmount(text)
            },
            {
                title: formatMessage({
                    id: 'detailTable.materialFee',
                    defaultMessage: '费用'
                }),
                dataIndex: 'materialFee',
                render: text => formatAmount(text)
            },
        ];
        return (
            <Table key="table"
                className="white-space-nowrap"
                rowKey={rowKey}
                columns={columns}
                pagination={false}
                loading={this.props.loading}
                dataSource={this.props.data || []}
                {...TABLE} />
        );
    }
}

DetailTable.defaultProps = {
    data: [],
};

DetailTable.propTypes = {
    data: PropTypes.array,
};
export default injectIntl(DetailTable);
